package ch03.demo.dao2.impl;

import net.sf.cglib.proxy.Enhancer;
import org.apache.log4j.Logger;

public class IntermediaryCglibProxyFactory {
    private static IntermediaryMethodInterceptor callback=new IntermediaryMethodInterceptor();
    private static Logger logger=Logger.getLogger(IntermediaryCglibProxyFactory.class);
    public static <T>T create(Class<T>target){
        Enhancer enhancer=new Enhancer();
        enhancer.setCallback(callback);
        enhancer.setSuperclass(target);
        return (T) enhancer.create();
    }

    public static void main(String[] args) {
        RealBuyer buyer=IntermediaryCglibProxyFactory.create(RealBuyer.class);
        String result=buyer.havealook();
        logger.debug(result);
    }
}
